#include"blockqueue.hpp"
#include"task.hpp"
#include<iostream>
#include<pthread.h>
#include<queue>
#include<ctime>
#include<stdlib.h>
#include<unistd.h>
#include<string>
using namespace std;

blockqueue<Task> bt;

void* producers(void* args)
{
    for(int i = 0; ; i++)
    {
        int data1 = rand() % 100;
        int data2 = rand() % 100;
        int ch = opers[rand()%4];
        Task t(data1,data2,ch);

        bt.push(t);
        cout << "生产一个数据," << "data: " <<endl;
        sleep(1);
    }
}

void* consumers(void* args)
{
    while(1)
    {
        Task t = bt.pop();
        cout << "消费一个数据,"<< "Task " <<t.GetTask()<< endl;
    }
    
}

int main()
{
    srand(time(nullptr));
    pthread_t c,p;
    pthread_create(&c,nullptr,consumers,nullptr);
    pthread_create(&p,nullptr,producers ,nullptr);


    pthread_join(c,nullptr);
    pthread_join(p,nullptr);

    return 0;
}